<?php
/**
 * licenses : MIT
 * creatTime: 2020/5/15
 * author : weblinuxgame
 * filename: UserRegisterController.php
 */

namespace App\Http\Controllers\JsonApi;


use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Api\Modules\User\RegisterApi;
use App\Api\Requests\User\UserRegister;
use App\Http\Controllers\JsonApiController;
use App\Repositories\UserRegisterRepository;

/**
 * Class UserRegisterController
 * @package App\Http\Controllers\JsonApi
 */
class UserRegisterController extends JsonApiController implements RegisterApi
{

    /**
     * 注册
     * @param Request $request
     * @return Response
     */
    public function register(Request $request): Response
    {
        $data = new UserRegister($request);
        if (!$data->check()) {
            return $this->failed($data->validator()->errors()->first(), -1);
        }
        $repository = new UserRegisterRepository();
        return $this->response($repository->register($data->toArray()));
    }
}
